package com.osfw.dbadminer.service.operlog.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.osfw.dbadminer.entity.operlog.DbaOperLog;
import com.osfw.dbadminer.mapper.operlog.DbaOperLogMapper;
import com.osfw.dbadminer.service.operlog.IDbaOperLogService;
import com.osfw.framework.utils.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 数据库SQL执行日志记录 服务层处理
 */
@Service
public class DbaOperLogServiceImpl extends ServiceImpl<DbaOperLogMapper, DbaOperLog> implements IDbaOperLogService {

    @Override
    public List<DbaOperLog> selectOperLogList(DbaOperLog operLog) {
        LambdaQueryWrapper<DbaOperLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(operLog.getConnectName()), DbaOperLog::getConnectName, operLog.getConnectName());
        queryWrapper.like(StringUtils.isNotEmpty(operLog.getDatabaseName()), DbaOperLog::getDatabaseName, operLog.getDatabaseName());
        queryWrapper.eq(StringUtils.isNotEmpty(operLog.getOperType()), DbaOperLog::getOperType, operLog.getOperType());
        queryWrapper.eq(operLog.getExecStatus() != null, DbaOperLog::getExecStatus, operLog.getExecStatus());
        queryWrapper.like(StringUtils.isNotEmpty(operLog.getOperUserName()), DbaOperLog::getOperUserName, operLog.getOperUserName());
        queryWrapper.eq(operLog.getOperDeptId() != null, DbaOperLog::getOperDeptId, operLog.getOperDeptId());
        queryWrapper.ge(operLog.getBeginTime() != null, DbaOperLog::getOperTime, operLog.getBeginTime());
        queryWrapper.le(operLog.getEndTime() != null, DbaOperLog::getOperTime, operLog.getEndTime());
        return list(queryWrapper);
    }

}
